import re

fileName=input("请输入文件名:")
oldLines=[]
newLines=[]

'''
1.读出文件各行数据存入oldLines 
'''
with open(fileName,'r') as f:
    oldLines=f.readlines()
'''

2.构建正则表达式、保留字仓、分隔符仓 
'''
pattern=re.compile("^[a-zA-z_]\w*") #以字母或下划线开头 包含字母 数字 下划线

keywords=[]
with open("keywords.txt",'r') as f:
    tempWords=f.read()
    keywords=tempWords.split(",")
splitSyn=[',',';','\(','\)','{','}','\s+','\.']
'''
3. 以行为单位进行判断
'''

for line in oldLines:
    tmpwords=re.sub('|'.join(splitSyn), '@@@', line).split('@@@')
    for word in tmpwords:
        result=re.match(pattern,word)
        realword=''
        if result is not None:
            realword=result.group()
        if realword not in keywords and realword:
            newLines.append(realword)

    
#4.写结果
with open('output.txt','w') as f:
    for line in newLines:
        f.write(line+"\n")
